package oiunt.hello;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout.LayoutParams;

public class PictureUtil extends Activity {
	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		
		LinearLayout linLayout = new LinearLayout(this); 
		Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), R.drawable.front);
		
		int width = bitmapOrg.getWidth();
		int height = bitmapOrg.getHeight();
		int newWidth = 400;
		int newHeight = 700;
		
		float scaleWidth = ((float)newWidth) / width;
		float scaleHeight = ((float)newHeight) / height;
		
		Matrix matrix = new Matrix();
		matrix.postScale(scaleWidth, scaleHeight);
		
		//recreate the bitmap
		Bitmap resizeBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true);
		BitmapDrawable bmd = new BitmapDrawable(resizeBitmap);
		ImageView img = new ImageView(this);
		img.setImageDrawable(bmd);
		img.setScaleType(ScaleType.CENTER);
		
		linLayout.addView(img, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		
		
		setContentView(linLayout);
	}
}
